package cuiyt.juc.reflaction;

/**
 * @author cyt
 * @create 2020-04-13 15:01
 */
public class Test01 {

    /**
     * 获得 对象的  Class
     * @param args
     * @throws ClassNotFoundException
     */
    public static void main(String[] args) throws ClassNotFoundException {
        Person p1 = new Stu();
        System.out.println("这个人是" + p1.name);
        // 1 getClass();
        Class p1Class = p1.getClass();
        System.out.println(p1Class.hashCode());
        // 2 Class.forName
        Class p2 = Class.forName("reflaction.Stu");
        System.out.println(p2.hashCode());
        // 3  Stu.class
        Class<Stu> aClass = Stu.class;
        System.out.println(aClass.hashCode());
        // 4 Integer.TYPE;
        Class<Integer> type = Integer.TYPE;
        System.out.println(type);
        // 5 getSuperclass();
        Class<? super Stu> superclass = aClass.getSuperclass();
        System.out.println(superclass);
    }
}


class Person {
    public String name;

    public Person() {
    }

    public Person(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                '}';
    }
}

class Stu extends Person {
    public Stu() {
        this.name = "学生";
    }
}

class Tea extends Person {
    public Tea() {
        this.name = "教师";
    }
}
